<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>律所收支录入</title>
    <link rel="stylesheet" href="../../layuiadmin/js/finance/js/bootstrap/css/bootstrap.min.css" />
    <script type="text/javascript" src="../../layuiadmin/js/finance/js/jquery.min.js" ></script>
    <script type="text/javascript" src="../../layuiadmin/js/finance/js/bootstrap/js/bootstrap.js" ></script>
    <script type="text/javascript" src="../../layuiadmin/layui/layui.js"></script>
    <script>
        $(document).ready(function(){
            demo();
            $.post("http://localhost:8080/financePayoutController/payouttypelist",function(msg){
                for(var i=0;i<msg.length;i++){
                    var payoutType=$("#payoutTypeId");
                    if(msg[i].pid==0){
                        var op=$("<option value='"+msg[i].payoutTypeId+"' disabled='false'>"+msg[i].payoutName+"</option>");
                    }else if(msg[i].pid!=100103){
                        var op = $("<option value='"+msg[i].payoutTypeId+"'>"+"&nbsp&nbsp----" + msg[i].payoutName + "</option>");
                    }else{
                        var op = $("<option value='"+msg[i].payoutTypeId+"'>"+"&nbsp&nbsp&nbsp&nbsp----" + msg[i].payoutName + "</option>");
                    }
                    payoutType.append(op);
                }
            });
            $.post("http://localhost:8080/financePayoutController/paytype",function(msg) {
                for(var i=0;i<msg.length;i++){
                    var paytype=$("#payId");
                    var op=$("<option value='"+msg[i].payId+"'>"+msg[i].payType+"</option>");
                    paytype.append(op);
                }
            });
        });
        function demo() {
            var sel=$("#sel").val();
            var name=$("#name").val();
            $.post("http://localhost:8080/financePayoutController/caselawlist",
                {"name":name,"sel":sel},
                function(msg){
                    var tab=$("#tab");
                    if (msg.length == 0) {
                        $("#tab  tr:not(:first)").remove();
                        var tr = $("<tr></tr>");
                        var td = $("<td colspan='7'>没有相关数据</td>");
                        tr.append(td);
                        tab.append(tr);
                    }else {
                        $("#tab  tr:not(:first)").remove();
                        for(var i=2;i<msg.length;i++){
                            var tr = $("<tr></tr>");
                            var td = $("<td><input type='radio' id='ca'  name='an' ></td>");
                            var td1 = $("<td>" + msg[i].caseId + "</td>");
                            var td2 = $("<td>" + msg[i].clientId.clientName + "</td>");
                            var td3 = $("<td>" + msg[i].oppositeId.clientName + "</td>");
                            var td4 = $("<td>" + msg[i].mainLawyer.empName + "</td>");
                            var td5 = $("<td>" + msg[i].closeDate + "</td>");
                            var td6=$("<td class='hidden'>"+msg[i].amountMoney+"</td>");
                            tr.append(td);
                            tr.append(td1);
                            tr.append(td2);
                            tr.append(td3);
                            tr.append(td4);
                            tr.append(td5);
                            tr.append(td6);
                            tab.append(tr);
                        }
                    }
                });
        }
        function check() {
            var caseid1= $('input[name="an"]:checked').parent().parent().find("td").eq(1).text();
            var caseid=$("#caseid").val(caseid1);
        }
        function sellist(){
            var casequery=$("#sel").val();
            var casetext=$("#name").val();
            $.post("http://localhost:8080/financePayoutController/caselawlist",
                {"casequery":casequery,"casetext":casetext},
                function (msg) {
                    var caseid=$("#caseid").val();
                    caseid=msg[i].caseId;
                });
        }
        function add() {
            var layer;
            var caseid=$("#caseid").val();
            var enteringDate=$("#enteringDate").val();
            var inoutMoney=$("#inoutMoney").val();
            var payoutTypeId=$("#payoutTypeId").val();
            var payer=$("#payer").val();
            var payId=$("#payId").val();
            var inoutperson=$("#inoutperson").val();
            var remark=$("#remark").val();
            $.post("http://localhost:8080/financePayoutController/incomepayer",{"empName":inoutperson},function (ms) {
                if(ms.length==0){
                    var span=$("#span").text("请正确输入收支人姓名");
                    var inoutperson=$("#inoutperson").val('');
                }else {
                    var inoutPerson=$("#inoutperson").val();
                    if(inoutPerson!=null&&inoutPerson!=''&&
                        caseid!=null&&caseid!=''&&
                        enteringDate!=null&& enteringDate!=''&&
                        inoutMoney!=null&&inoutMoney!=''&&
                        payoutTypeId!=null&& payoutTypeId!=''&&
                        payer!=null&&payer!=''&&
                        payId!=null&&payId!=''&&
                        remark!=null&&remark!=''){
                        $.post("http://localhost:8080/financeIncomeController/caselist",{"caseid":caseid},function (msg) {
                            $.post("http://localhost:8080/financePayoutController/addpayout",
                                {
                                    "caseId": caseid,
                                    "enteringDate": enteringDate,
                                    "inoutMoney": inoutMoney,
                                    "payoutTypeId": payoutTypeId,
                                    "payer": payer,
                                    "payId": payId,
                                    "inoutPerson":msg.mainLawyer.empId,
                                    "remark": remark
                                },
                                function (data) {
                                    if (data == 1) {
                                        alert("提交成功");
                                    } else {
                                        alert("提交失败");
                                    }
                                });
                        });
                    }else{
                        alert("提交失败,信息请填写完整");
                    }

                }
            });

        }
    </script>
</head>
<body>
<div class="container-fluid">
    <form class="form-horizontal form-inline" >
        <div style="margin-top: 15px">
            <div class="row">
                <div class="col-lg-12">
                    <div class="col-lg-1"></div>
                    <div class="col-lg-11">
                        <font style="font-size: 20px"><strong>|律所收支</strong></font><br>
                    </div>
                </div>
                <div class="col-lg-12">
                    <br>
                    <div class="col-lg-1"></div>
                    <div class="col-lg-5">
                        <label><font style="color: red">*</font>案件</label>
                        <br>
                        <input type="text"  data-toggle="modal" data-target="#mt" class="form-control" style="width:100%" id="caseid" readonly="readonly">
                    </div>
                    <div class="col-lg-6">
                        <label><font style="color: red">*</font>收支日期</label>
                        <br>
                        <input type="date" class="form-control" style="width: 100%" id="enteringDate">
                    </div>
                </div>
                <div class="col-lg-12">
                    <br>
                    <div class="col-lg-1"></div>
                    <div class="col-lg-5">
                        <label for="inoutMoney"><font style="color: red">*</font>收支金额</label>
                        <br>
                        <input type="text" id="inoutMoney" class="form-control" style="width:100%">
                    </div>
                    <div class="col-lg-6">
                        <label for="payoutTypeId"><font style="color: red">*</font>收支类别</label>
                        <br>
                        <select class="form-control" id="payoutTypeId" style="width: 100%">
                            <option value="-1">请选择收支类型</option>
                        </select>
                    </div>
                </div>
                <div class="col-lg-12">
                    <br>
                    <div class="col-lg-1"></div>
                    <div class="col-lg-5">
                        <label for="payer"><font style="color: red">*</font>付款人</label>
                        <br>
                        <input type="text" id="payer" class="form-control" style="width: 100%">
                    </div>
                    <div class="col-lg-6">
                        <label for="payId"><font style="color: red">*</font>支付方式</label>
                        <br>
                        <select class="form-control" id="payId" style="width: 100%">
                            <option value="-1">请选择支付类型</option>
                        </select>
                    </div>
                </div>
                <div class="col-lg-12">
                    <br>
                    <div class="col-lg-1"></div>
                    <div class="col-lg-5">
                        <label for="inoutperson"><font style="color: red">*</font>收支人</label>
                        <br>
                        <input type="text" id="inoutperson" class="form-control" style="width: 100%">
                        <font style="color: red;"><span id="span"></span></font>
                    </div>
                </div>
                <div class="col-lg-12">
                    <br>
                    <div class="col-lg-1"></div>
                    <div class="col-lg-11">
                        <label for="payer">备注</label>
                        <br>
                        <textarea id="remark" style="width: 100%"></textarea>
                    </div>
                </div>
                <div class="col-lg-12">
                    <br>
                    <div class="col-lg-1"></div>
                    <div class="col-lg-11">
                        <button type="button" class="btn btn-success" onclick="add()">确认提交</button>
                    </div>
                </div>
            </div>
        </div>
        <div class="modal"  id="mt">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <span>选择案件</span>
                        <button class="close" data-dismiss="modal">
                            <span>&times;</span>
                        </button>
                    </div>
                    <div class="modal-body" style="height: 500px">
                        <div class="row"  style="padding-left: 20px" >
                            <input type="text" class="form-control" id="name"/>
                            <select class="form-control" id="sel">
                                <option value="1">案号搜索</option>
                                <option value="2">承办律师搜索</option>
                                <option value="3">委托人搜索</option>
                                <option value="4">对方当事人搜索</option>
                                <option value="5">案由搜索</option>
                                <option value="6">受理法院搜索</option>
                            </select>&nbsp;&nbsp;
                            <input type="button" class="btn btn-primary" value="搜索" onclick="demo()">
                        </div>
                        <div class="row"  style="padding-left: 20px;margin-top: 30px;" >
                            <table style="width: 97%;border: none;text-align: center" border="1px" id="tab">
                                <tr style="height: 50px">
                                    <td><b>选择</b></td>
                                    <td><b>案件号</b></td>
                                    <td><b>委托人</b></td>
                                    <td><b>对方当事人</b></td>
                                    <td><b>承办律师</b></td>
                                    <td><b>收案日期</b></td>
                                </tr>
                            </table>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <input type="button" class="btn btn-success"   value="确定" data-dismiss="modal" onclick="check()">
                        <input type="button" class="btn btn-success" value="关闭" data-dismiss="modal">
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
</body>
</html>